<template>
  <div class="web-layout">
    <el-container>
      <el-header height="60px">
        <div class="header">
          <h1>Web端</h1>
          <el-menu
            mode="horizontal"
            :default-active="active"
            @select="onSelect"
          >
            <el-menu-item index="/">首页</el-menu-item>
            <el-menu-item index="/user">用户中心</el-menu-item>
          </el-menu>
        </div>
      </el-header>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
  </div>
</template>

<script lang="ts" setup>
import { ref } from "vue";
import { useRouter, useRoute } from "vue-router";

const router = useRouter();
const route = useRoute();
const active = ref(route.path);

const onSelect = (index: string) => {
  router.push(index);
};
</script>

<style lang="scss">
// 添加 :global 防止样式被模块化
:global(.el-header) {
  height: 60px !important;
  line-height: 60px !important;
}

:global(.el-main) {
  padding: 20px !important;
}
</style>

<style lang="scss" scoped>
@use "@/styles/variables.scss" as *;
h1 {
  width: 100px;
}
.web-layout {
  min-height: 100vh;

  .header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    height: $header-height;
  }

  .el-main {
    max-width: $desktop-width;
    margin: 0 auto;
  }
}
</style>
